package com.gjy.elasticjob.job;

import org.apache.shardingsphere.elasticjob.api.ShardingContext;
import org.apache.shardingsphere.elasticjob.simple.job.SimpleJob;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.time.LocalDateTime;

/**
 * @author gjy
 * @version 1.0
 * @since 2025-08-27 12:26:57
 */
public class ShardedTaskSimpleJob implements SimpleJob {
    private static final Logger log = LoggerFactory.getLogger(ShardedTaskSimpleJob.class);

    @Override
    public void execute(ShardingContext context) {
        int shardingItem = context.getShardingItem();
        int count = context.getShardingTotalCount();
        String shardingParameter = context.getShardingParameter();
        String taskId = context.getTaskId();
        log.info("context: {}, classloader:{}", context.getJobParameter(), this.getClass().getClassLoader());
        log.info("分片{}/{} | 参数: {} | 任务ID: {}", shardingItem, count, shardingParameter, taskId);
        if (shardingItem == 0) {
            log.info("0 发送数据 : {} {}", LocalDateTime.now(),context.getShardingItem());
        }else {
            log.info("处理数据 : {} {}", LocalDateTime.now(),context.getShardingItem());
        }
    }

}
